﻿using Studio77.Timer.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// “用户控件”项模板在 http://go.microsoft.com/fwlink/?LinkId=234236 上提供

namespace Studio77.Timer
{
    public sealed partial class TimerItemView : UserControl
    {
        public TimerItemView()
        {
            this.InitializeComponent();
            this.Loaded += TimerItemView_Loaded;
        }

        void TimerItemView_Loaded(object sender, RoutedEventArgs e)
        {
            this.Loaded -= TimerItemView_Loaded;
            this.btnDelete.Click += btnDelete_Click;
            this.Tapped += TimerItemView_Tapped;
        }

        void TimerItemView_Tapped(object sender, TappedRoutedEventArgs e)
        {
            (this.DataContext as TimerItemViewModel).IsStoped = !(this.DataContext as TimerItemViewModel).IsStoped;
            if ((this.DataContext as TimerItemViewModel).IsStoped)
            {
                (this.DataContext as TimerItemViewModel).TxtBrush = new SolidColorBrush(Color.FromArgb(255, 255, 255, 0));
            }
            else
            {
                (this.DataContext as TimerItemViewModel).TxtBrush = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
            }
        }

        void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            MainPage.instance.timerItems.Remove(this.DataContext as TimerItemViewModel);
        }
    }
}
